<template>
  <div id="store_verification">
    <c-title text="多商户核销"></c-title>
    <van-tabs v-model="active" title-active-color="#ce811d" color="#ce811d" @click="btnSelect">
      <van-tab :title="titled">
        <div class="location" @click.stop="tolocation" v-if="tabsShow">
          <i class="iconfont icon-fontclass-dizhi"></i>
          <span class="address_name">{{ address || "全国" }}</span>
          <van-icon name="arrow-down" />
        </div>
        <div class="order_by">
          <span v-for="(item, index) in orderbyList" :key="index" class="order_by_item">
            <span :class="item.state == 'rise' || item.state == 'drop' ? 'order_by_active' : ''">{{ item.name }}</span>
            <div class="order_by_icon">
              <i class="el-icon-caret-top" @click="orderBy(item.name, 'rise')" :class="item.state == 'rise' ? 'order_by_active' : ''"></i>
              <i class="el-icon-caret-bottom" @click="orderBy(item.name, 'drop')" :class="item.state == 'drop' ? 'order_by_active' : ''"></i>
            </div>
          </span>
        </div>
        <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getIncomplete">
          <van-cell v-for="(item, key) in incompleteList" :key="key" style="margin: 1rem 0;">
            <div class="project_detail" style="background: #fff;">
              <div class="bottom" @click.stop="to_project_detail(item.project_id)">
                <img :src="item.project_thumb" alt="" />
                <div class="middle">
                  <span class="project_name">{{ item.project_title }}</span>
                  <div class="num">
                    <span v-if="item.check_type != 2">总次数：{{ item.total_count }}</span>
                    <span>已使用：{{ item.used_count }}</span>
                  </div>
                  <span class="verification_name" :style="{ color: item.near_ending === 1 ? '#f14e4e' : '#3486d3' }">到期使用时间：{{ item.end_time }}</span>
                </div>
                <div class="rigth" v-if="item.check_type != 2">
                  <div v-if="item.rest_count != '无限'">
                    <span class="num">{{ item.rest_count }}</span
                    >次
                  </div>
                  <div v-else>
                    <div class="num" style="white-space: nowrap;display: flex;align-items: flex-end;">{{ item.rest_count }}<span style="line-height: 13px;font-size: 13px;color:#000;">次</span>
                    </div>
                  </div>
                  <span class="verification_num">未使用</span>
                </div>
              </div>
              <div class="write_off_new">
                <span class="write_off_record" @click="btnVerUser(item.project_title)">使用记录</span>
                <span class="write_off_user" @click="btnUsere(item)">核销使用</span>
                <span class="give" @click="tapBtnGive(item)" v-if="item.transfer_open">转赠</span>
                <span class="appointment" @click="showAppointmentOpen(item)" v-if="item.expect_status == 1">预约</span>
              </div>
              <template v-if="isHideStore">
                <div class="write_off_store">
                  <span class="line"></span>
                  <span class="service_store">该{{ projectName }}附近可核销商户</span>
                </div>
                <div class="store">
                  <img :src="item.store_thumb" alt="" />
                  <div class="store_detail">
                    <span class="store_name">{{ item.store_name }}</span>
                    <span class="date">营业时间:{{ item.store_business_hours_start }}-{{ item.store_business_hours_end }}</span>
                    <div class="location_detail">
                      <div class="store_location">
                        <i class="iconfont icon-order_locate"></i>
                        <span class="address_name">{{ item.store_full_address }}</span>
                      </div>
                      <span>{{ item.store_distance }}{{ item.store_distance_unit }}</span>
                    </div>
                  </div>
                </div>
                <div class="more"><span class="see_more" @click="seeMore(item)">查看更多商户</span><van-icon name="arrow" /></div>
              </template>
            </div>
          </van-cell>
        </van-list>
        <serviceCard @hide_store='hide_store'></serviceCard>
      </van-tab>
      <van-tab :title="titleIng">
        <van-list v-model="loading_completed" :finished="finished_completed" finished-text="没有更多了" @load="getCompleted" :immediate-check="false" v-if="!tabsShow">
          <van-cell v-for="(item, key) in completed" :key="key">
            <div class="complete">
              <div class="bottom">
                <img :src="item.project_thumb" alt="" />
                <div class="middle">
                  <span class="project_name">{{ item.project_title }}</span>
                  <div class="num">
                    <span v-if="item.check_type != 2">总次数：{{ item.total_count }}</span>
                    <span>已使用：{{ item.used_count }}</span>
                  </div>
                  <span class="fished_time">已完成时间：{{ item.finish_time }}</span>
                </div>
              </div>
              <div class="write_off_new">
                <span class="write_off_record">已完成</span>
                <span class="write_off_user" @click="btnVerUser(item.project_title)">使用记录</span>
                <span class="write_off_record" style="border: 0.1rem solid #F15353;" @click="toLink">评价</span>
              </div>
            </div>
          </van-cell>
        </van-list>
      </van-tab>
    </van-tabs>

    <van-popup v-model="showGivePop" style="width: 70%;" round class="give-pop" :close-on-click-overlay="false">
      <div class="frame-box">
        <div class="give-title">{{ projectName }}转赠</div>
        <div class="user-input">
          <van-field @keyup="throttleFn" v-model="giveUserId" label="用户id" placeholder="请输入赠送的用户id" required style="display: block;" />
          <div :class="['other', { error: nickname === '查无此用户' }]" v-show="nickname && giveUserId">
            <template v-if="nickname != '查无此用户'">昵称：</template>
            {{ nickname }}
          </div>
        </div>
        <div class="give-num-input">
          <van-field @input="changeNumInput" v-model="giveNum" label="转赠次数" placeholder="请输入转赠次数" required style="display: block;" />
          <div :class="['other', { error: giveNum }]" v-show="giveNum">
            <span>{{ errorNum }}</span>
          </div>
        </div>

        <div class="line"></div>
        <div class="bottom-btns">
          <div class="btn cancel" @click="closeGivePop">取消</div>
          <div class="btn comfirm" @click="giveProject">确定</div>
        </div>
      </div>
    </van-popup>
    <van-popup v-model="showAppointment" style="width: 15.63rem;" round :close-on-click-overlay="false">
      <div class="appointmentBox">
        <div class="title">预约</div>
        <div class="cellBox" @click="showAppointment_Store = true">
          <div class="cell_l">门店</div>
          <div class="cell_r" v-if="Appointment_Store.radio.length <= 0">请选择<van-icon name="arrow" /></div>
          <div class="cell_r" v-else >{{ storeNameCheck }}</div>
        </div>
        <div class="cellBox" @click="showAppointment_TimeOpen">
          <div class="cell_l">预约时间</div>
          <div class="cell_r" v-if="!Appointment_Store.selectTime">请选择<van-icon name="arrow" /></div>
          <div class="cell_r" v-else >{{ selectTime_Fittle }}</div>
        </div>
        <div class="bootom">
          <div class="bottom_l" @click="showAppointment_Tap_Cancel">取消</div>
          <div class="bottom_r" @click="showAppointment_Tap_confirm">确定</div>
        </div>
      </div>
    </van-popup>
    <van-popup v-model="showAppointment_Time" style="height: 25rem;" round :close-on-click-overlay="false" position="bottom">
      <van-nav-bar title="选择时间" @click-left="onClickLeft" @click-right="onClickRight" v-if="!showAppointment_Time_select">
        <template #left>
          <span>取消</span>
        </template>
        <template #right>
          <span>确定</span>
        </template>
      </van-nav-bar>
      <div class="pickerBox" v-if="!showAppointment_Time_select">
        <div class="pickBox flex-j-sb" @click="showAppointment_Time_select = true">
          <div class="pickBox_l">日期</div>
          <div class="pickBox_r">{{timeFittle}}<van-icon name="arrow" /></div>
        </div>
        <div class="pickBoxTimeLis">
          <div class="pickBoxTimeLis_ls" :class="[timeClass(item)]" @click="tapStoreTime(item)" v-for="item in timeList" :key="item.id">
            <span class="text" v-if="item.is_full == 1">约满</span>
            <div class="times">{{item.start_hour}}-{{item.end_hour}}</div>
          </div>
        </div>
      </div>
      <van-datetime-picker @cancel="time_cancel" @confirm="time_confirm" v-if="showAppointment_Time_select" v-model="Appointment_Store.DaySelect" type="date" title="选择年月日" :min-date="minDate" :max-date="maxDate"> </van-datetime-picker>
    </van-popup>
    <van-popup v-model="showAppointment_Store" :style="{ height: '36.16rem' }" round :close-on-click-overlay="false" position="bottom">
      <div class="storePopup">
        <van-nav-bar title="选择门店" @click-left="onClickLeft1" @click-right="onClickRight1">
          <template #left>
            <span>取消</span>
          </template>
          <template #right>
            <span>确定</span>
          </template>
        </van-nav-bar>
        <van-search v-model="Appointment_Store.keyword" show-action placeholder="搜索门店" @search="onSearch">
          <template #action>
            <div @click="onSearch">搜索</div>
          </template>
        </van-search>
        <div class="listBox">
          <van-checkbox-group v-model="Appointment_Store.radio">
            <div class="lis" v-for="item in Appointment_Store.list" :key="item.id" @click="tapStore(item)">
              <div class="lis_l">
                <img :src="item.thumb" alt="" />
              </div>
              <div class="lis_r">
                <div class="title">{{item.store_name}}</div>
                <div class="time">工作时间：{{item.start_hour}}-{{item.end_hour}}</div>
              </div>
              <div class="lis_radio">
                <van-checkbox  :name="item.id"></van-checkbox >
              </div>
            </div>
            <div class="moreTxt" v-if="Appointment_Store.page < Appointment_Store.last_page" @click="TapMore">加载更多</div>
            <van-empty image="search" v-if="Appointment_Store.list.length <= 0" description="描述文字" />
          </van-checkbox-group>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import my_project_controller from "./my_project_controller";

export default my_project_controller;
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
#store_verification {
  .location {
    display: flex;
    background: #fff;
    padding: 0.5rem 1rem;
    align-items: center;

    .iconfont {
      color: #f14e4e;
    }

    .address_name {
      margin: 0 0.46rem 0 0.46rem;
      color: #f14e4e;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
    }

    .van-icon {
      color: #f14e4e;
    }
  }

  .location_detail {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    color: #ce811d;

    .store_location {
      display: flex;
      background: #fff;
      align-items: center;
      width: 10.71rem;

      .address_name {
        margin: 0 0.46rem 0 0.46rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: block;
      }
    }
  }

  .project_detail {
    background: #fff;

    .write_off {
      display: flex;
      justify-content: space-around;
      padding: 1.07rem 0;

      .write_off_record {
        border-radius: 0.1rem;
        border: 0.1rem solid #ce811d;
        color: #ce811d;
        padding: 0.2rem 1.5rem;
      }

      .write_off_user {
        background-color: #ce811d;
        border: 0.1rem solid #ce811d;
        border-radius: 0.1rem;
        color: #fff;
        padding: 0.2rem 1.5rem;
      }

      .give {
        background-color: #f14e4e;
        border-radius: 0.1rem;
        color: #fff;
        padding: 0.2rem 2.5rem;
      }
      
    }
    

    .write_off_store {
      margin-bottom: 1.18rem;
      display: flex;
      align-items: center;

      .line {
        width: 0.2rem;
        height: 1.07rem;
        display: block;
        background-color: #ce811d;
        border-radius: 0.07rem;
        margin-right: 0.5rem;
      }

      .service_store {
        color: #202020;
        font-size: 18px;
      }
    }

    .store {
      display: flex;
      padding-bottom: 1.07rem;

      img {
        width: 5rem;
        height: 5rem;
        border-radius: 0.36rem;
        margin: 0;
      }

      .store_detail {
        display: flex;
        flex-direction: column;
        text-align: left;
        justify-content: space-between;
        margin-left: 1rem;

        .store_name {
          font-size: 14px;
          color: #202020;
        }

        .date {
          color: #666;
        }
      }
    }

    .more {
      display: flex;
      align-items: center;
      justify-content: center;

      .see_more {
        margin-right: 1rem;
      }
    }
  }

  .complete {
    background: #fff;
  }

  .bottom {
    display: flex;
    text-align: left;
    align-items: center;

    img {
      width: 4.71rem;
      height: 4.71rem;
      border-radius: 0.36rem;
      margin: 0;
      margin-right: 0.61rem;
    }

    .middle {
      width: 100%;

      .project_name {
        color: #333;
        font-size: 14px;
        text-align: left;
        font-weight: bold;
        word-break: break-all;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
      }

      .num {
        display: flex;
        margin: 0.3rem 0 0.3rem 0;
        color: #ce811d;
        justify-content: space-between;
        font-size: 12px;
      }

      .verification_name {
        display: flex;
        color: #f14e4e;
        font-size: 14px;
        text-align: left;
      }

      .fished_time {
        display: flex;
        font-size: 16px;
        text-align: left;
        color: #666;
      }
    }

    .rigth {
      display: flex;
      flex-direction: column;
      margin-left: 0.5rem;
      text-align: right;
      justify-content: center;
      align-items: center;

      .num {
        color: #ce811d;
        font-size: 26px;
        text-align: center;
      }

      .verification_num {
        color: #ce811d;
        width: 3.43rem;
        text-align: center;
      }
    }
  }

  .write_off {
    display: flex;
    justify-content: space-between;
    padding: 1.07rem 1.11rem;

    .write_off_record {
      border-radius: 0.1rem;
      color: #ce811d;
      padding: 0.2rem 2.5rem;
    }

    .write_off_user {
      background-color: #ce811d;
      border-radius: 0.1rem;
      color: #fff;
      padding: 0.2rem 2.5rem;
    }
  }

  .suspension {
    display: flex;
    flex-direction: column;
    position: fixed;
    bottom: 10%;
    transform: translateX(10rem);
    right: 50%;

    img {
      width: 2.5rem;
      height: 2.5rem;
      margin-bottom: 1.21rem;
    }
  }
}

.give-pop {
  padding: 1rem 1rem 0 1rem;

  .give-title {
    font-size: 1.06rem;
    color: #2c2c2c;
  }

  .other {
    width: 90%;
    margin: 0 auto 0.875rem;
    text-align: left;
    color: #ce811d;
    font-size: 12px;
  }

  .error {
    color: #f14e4e;
  }

  .give-num-input {
    margin: 0.5rem 0 2rem 0;
  }

  .line {
    height: 1px;
    background-color: #d9dbdd;
    transform: scaleY(0.5);
  }

  .bottom-btns {
    display: flex;
    align-items: center;
    height: 2.5rem;

    .btn {
      flex: 1;
      height: 100%;
      line-height: 2.5rem;
    }

    /* .cancel {} */

    .comfirm {
      color: #f14e4e;
    }
  }
}

.order_by_active {
  color: #ce8222;
}

.order_by {
  display: flex;
  justify-content: space-around;
  margin: 10px 0;

  .order_by_item {
    display: flex;

    .order_by_icon {
      display: flex;
      flex-direction: column;
      justify-content: center;

      i {
        line-height: 8px;
      }
    }
  }
}
// 预约选择时间
.pickerBox {
  padding: 0 0.75rem;
  box-sizing: border-box;
  .pickBox {
    margin: 1.56rem 0;
    align-items: center;
    .pickBox_l {
      font-weight: bold;
      font-size: 0.88rem;
    }
    .pickBox_r {
      font-weight: 500;
      font-size: 0.88rem;
    }
  }
  .pickBoxTimeLis {
    display: flex;
    flex-wrap: wrap;
    .pickBoxTimeLis_ls {
      flex-shrink: 0;
      border-radius: 0.38rem;
      width: 6.78rem;
      height: 2.5rem;
      text-align: center;
      line-height: 2.5rem;
      border: 0.03rem solid #d6d6dc;
      margin-right: 0.66rem;
      margin-bottom: 0.63rem;
      position: relative;
      .times {
        color: #00001c;
        font-weight: 500;
        font-size: 0.81rem;
      }
      .text {
        position: absolute;
        right: 0;
        top: 0;
        width: 2.03rem;
        height: 1.34rem;
        clip-path: polygon(0 0, 100% 0, 100% 100%);
        background: #f15353;
        border-radius: 0 0.35rem;
        color: #fff;
        text-align: right;
        line-height: 0.9rem;
        font-size: 0.5rem;
        padding-right: 0.1rem;
        vertical-align: middle;
      }
    }
    .select {
      border: 0.03rem solid #f15353;
      .times {
        color: #f15353;
      }
    }
    .full {
      .times {
        color: #d6d6dc;
      }
    }
    .pickBoxTimeLis_ls:nth-child(3n) {
      margin-right: 0;
    }
  }
}
//预约选择门店
.storePopup {
  width: 100%;
  // height: 36.16rem;
  overflow: hidden;
  background: #fff;
  .listBox {
    display: flex;
    flex-direction: column;
    padding: 0 0.75rem;
    .lis {
      padding: 0.94rem 0;
      border-bottom: 1px solid #f5f5f5;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .moreTxt{
        text-align: center;
      }
      .lis_l {
        flex-shrink: 0;
        width: 3.13rem;
        height: 3.13rem;
        border-radius: 0.5rem;
        margin-right: 0.63rem;
        img {
          width: 100%;
          height: 100%;
          border-radius: 0.5rem;
        }
      }
      .lis_radio {
        flex: 1;
        display: flex;
        justify-content: flex-end;
      }
      .lis_r {
        width: 10.41rem;
        flex-shrink: 0;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        .title {
          font-weight: 500;
          font-size: 0.88rem;
        }
        .time {
          font-size: 0.75rem;
          color: #999999;
          margin-top: 0.5rem;
        }
      }
    }
    .moreTxt{
      padding-top: 1rem;
      text-align: center;
      color: #999;
    }
  }
}
//预约弹窗
.appointmentBox {
  padding: 1.06rem 0 0 0;
  box-sizing: border-box;
  .title {
    margin-bottom: 0.75rem;
    font-weight: bold;
    font-size: 1rem;
    color: #00001c;
  }
  .cellBox {
    margin: 0 0.63rem;
    padding: 0.84rem 0.5rem;
    box-sizing: border-box;
    border: 1px solid #e5e5e5;
    border-radius: 0.63rem;
    font-size: 0.81rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.59rem;
    .cell_l {
      font-weight: 500;
    }
    .cell_r {
      color: #aaaab3;
      text-align: right;
    }
  }
  .cellBox:last-child {
    margin-bottom: 0;
  }
  .bootom {
    height: 2.68rem;
    border-top: 1px solid #ececec;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.97rem;
    .bottom_l {
      height: 2.68rem;
      flex: 1;
      text-align: center;
      line-height: 2.68rem;
      color: #7e7e7e;
      border-right: 1px solid #ececec;
    }
    .bottom_r {
      height: 2.68rem;
      flex: 1;
      text-align: center;
      line-height: 2.68rem;
      color: #fe5e56;
    }
  }
}
.write_off_new{
  display: flex;
  flex-wrap: wrap;
  margin: 1.13rem 0;
  span{
    flex-shrink: 0;
    width: calc((100% - 1.26rem) / 3);
    height: 1.88rem;
    margin: 0 0.63rem 0.63rem 0;
    border-radius: 0.19rem;
    text-align: center;
    line-height: 1.88rem;
  }
  span:nth-child(3n){
    margin-right: 0;
  }
  .write_off_record {
    border: 0.1rem solid #ce811d;
    color: #ce811d;
  }
  .write_off_user {
    background-color: #ce811d;
    border: 0.1rem solid #ce811d;
    color: #fff;
  }
  .give {
    background-color: #f14e4e;
    color: #fff;
    border: 0.1rem solid #f14e4e;
  }
  .appointment {
    border: 0.1rem solid #F15353;
    color: #F15353;
  }
}
</style>
